package com.tcat.user.mapper;

import com.tcat.user.pojo.Roles;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface RoleMapper extends Mapper<Roles> {
    @Insert("INSERT INTO tb_rps(rid,pid) VALUES (#{rid},#{pid})")
    int insertRps(@Param("rid") Long rid, @Param("pid") Long pid);

    /**
     * 根据uid删除中间表相关数据
     * @param rid
     */
    @Delete("DELETE FROM tb_rps WHERE rid=#{rid}")
    void deleteByRolesInRps(@Param("rid") Long rid);

    @Delete("DELETE FROM tb_urs WHERE rid=#{rid}")
    void deleteByRolesInUrs(@Param("rid") Long rid);
    /**
     * 根据用户id查询角色
     * * @param uid
     * @return
     */
    @Select("SELECT * FROM tb_roles WHERE role_id IN(SELECT rid FROM tb_urs Where uid = #{uid})")
    List<Roles> queryByUserId(@Param("uid") Long uid);

}
